/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.report.service.impl;

import com.koron.common.bean.DepartmentTreeBean;
import com.koron.common.bean.StaffBean;
import com.koron.common.web.Util;
import com.koron.hazardsource.mapper.IndicationItemsMapper;
import com.koron.hiddendanger.domain.HiddenDangerDiscovery;
import com.koron.hiddendanger.domain.HiddenDangerRectification;
import com.koron.hiddendanger.mapper.CheckRecordMapper;
import com.koron.hiddendanger.mapper.HiddenDangerMapper;
import com.koron.hiddendanger.uitls.OverdueJudgmentUtil;
import com.koron.report.bean.*;
import com.koron.report.mapper.DataAnalysisMapper;
import com.koron.report.service.api.DangerAnalysisService;
import com.koron.report.util.BusinessCode;
import com.koron.risk.bean.CorpBean;
import com.koron.risk.mapper.CorpManagementMapper;
import com.koron.risk.service.api.CorpManagementService;
import com.koron.risk.service.api.GridNodeService;
import com.koron.risk.service.api.HazardSourceDistributeService;
import com.koron.system.domain.DictData;
import com.koron.system.domain.DictType;
import com.koron.system.domain.District;
import com.koron.system.domain.DistrictCorpRelation;
import com.koron.system.mapper.DictDataMapper;
import com.koron.system.mapper.DistrictMapper;
import com.koron.system.service.api.DictTypeService;
import com.koron.system.service.api.DistrictService;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.swan.bean.MessageBean;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class DangerAnalysisServiceImpl implements DangerAnalysisService, InitializingBean {

    private final static  Logger logger = LoggerFactory.getLogger(DangerAnalysisServiceImpl.class);

    @Autowired
    private DistrictService districtService;

    @Autowired
    private CorpManagementService corpManagementService;

    @Autowired
    private HazardSourceDistributeService sourceService;

    @Autowired
    private Util util;

    @Autowired
    private DictTypeService dictTypeService;

    private Map<String, String> map = new HashMap<>();

    private Map<String, String> dictNameMap = new HashMap<>();

    private Map<String, String> dictCodeMap = new HashMap<>();

    private Map dictQueryMap = new HashMap<>();

    private Map<String, String> accidentTypeMap = new HashMap<>();

    private List<String> nodeList = Arrays.asList("0f92c31a7bdf4199aef13f1525e80f88", "2977d7c012e74b8e91a4a7ae16e0d65e",
            "a961752329aa4614ad4d78e53b28f76b", "e137bf5392ae48859429012500f6d2d0", "e5919a66cedc4067bb1f9218d648d72d");

    @Autowired
    private GridNodeService nodeService;

    @Override
    public MessageBean<List<DangerAnalysis>> queryCountDanger(Date updateTimeStart, Date updateTimeEnd, String code) {
        MessageBean<List<DangerAnalysis>> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            if (null == map || map.isEmpty()) {
                setMap();
            }
            if (null == map || map.isEmpty()) {
                msg.setCode(-1);
                msg.setDescription("统计项基础数据为空，无法进行统计");
                return msg;
            }
            List<DangerAnalysis> dangerAnalysisList = new ArrayList<>();
            //判断是否传入了片区code
            if (StringUtils.isEmpty(code)) {
                generateDangerAnalysis(dangerAnalysisList, factory, null, updateTimeStart, updateTimeEnd);
            } else {
                //查询指定code的直接下属部门
                List<DepartmentTreeBean> departmentTreeBeanList = (List<DepartmentTreeBean>) util.depttree(code, 0).getData();
                if (null != departmentTreeBeanList && departmentTreeBeanList.size() > 1) {
                    for (int i = 1; i < departmentTreeBeanList.size(); i++) {
                        DepartmentTreeBean departmentTreeBean = departmentTreeBeanList.get(i);
                        generateDangerAnalysis(dangerAnalysisList, factory, departmentTreeBean, updateTimeStart, updateTimeEnd);
                    }
                } else {
                    //没有下级部门，直接返回当前部门的数据
                    if (departmentTreeBeanList.size() == 1) {
                        generateDangerAnalysis(dangerAnalysisList, factory, departmentTreeBeanList.get(0), updateTimeStart, updateTimeEnd);
                    }
                    if (dangerAnalysisList != null)
                        dangerAnalysisList.get(0).setExistChild(0);
                }
            }
            msg.setCode(BusinessCode.SUCCESS.getCode());
            msg.setDescription("查询隐患的统计数据成功");
            msg.setData(dangerAnalysisList);
            return msg;
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }

    @Override
    public MessageBean<DangerAnalysis> countDanger(Date updateTimeStart, Date updateTimeEnd, String code) {
        MessageBean<DangerAnalysis> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            if (null == map || map.isEmpty()) {
                setMap();
            }
            if (null == dictQueryMap || dictQueryMap.isEmpty()) {
                getTable();
            }
            if (null == map || map.isEmpty()) {
                msg.setCode(-1);
                msg.setDescription("统计项基础数据为空，无法进行统计");
                return msg;
            }
            if (null == dictQueryMap || dictQueryMap.isEmpty()) {
                msg.setCode(-1);
                msg.setDescription("统计项基础数据为空，无法进行统计");
                return msg;
            }
            List<DangerAnalysis> dangerAnalysisList = new ArrayList<>();
            //先获取各个状态的id
            if (StringUtils.isEmpty(code)) {
                //查询所有数据
                generateDangerAnalysis(dangerAnalysisList, factory, null, updateTimeStart, updateTimeEnd);
            } else {
                //查询指定code的直接下属部门
                List<DepartmentTreeBean> departmentTreeBeanList = (List<DepartmentTreeBean>) util.depttree(code, 0).getData();
                //第一条数据就是当前部门的数据
                if (departmentTreeBeanList != null && departmentTreeBeanList.size() > 0)
                    generateDangerAnalysis(dangerAnalysisList, factory, departmentTreeBeanList.get(0), updateTimeStart, updateTimeEnd);
            }
            msg.setData(dangerAnalysisList == null || dangerAnalysisList.size() <= 0 ? null : dangerAnalysisList.get(0));
            return msg;
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }

    private void generateDangerAnalysis(List<DangerAnalysis> dangerAnalysisList, SessionFactory factory, DepartmentTreeBean departmentTreeBean, Date updateTimeStart, Date updateTimeEnd) {
        //查询当前部门下的所有网格（包括网格和部门）,不包含自己本身
        List<String> codeList = new ArrayList<>();
        if (departmentTreeBean != null) {
            codeList = nodeService.getChildCodeList(departmentTreeBean.getDepartmentCode());
            if (codeList == null)
                codeList = new ArrayList<>();
            codeList.add(departmentTreeBean.getDepartmentCode());
        }
        DangerAnalysis dangerAnalysis = factory.getMapper(DataAnalysisMapper.class).queryCountDangerByGrid(map.get("nomarlDangerCount"), map.get("importantDangerCont"), map.get("managerDangetCount"),
                map.get("deviceDangerCount"), map.get("meterialDangerCount"), map.get("personDangerCount"), map.get("goodsDangerCount"),
                map.get("enviropmentDangerCount"), updateTimeStart, updateTimeEnd, codeList);
        DangerAnalysis dangerAnalysis1 = factory.getMapper(DataAnalysisMapper.class).queryCountDangerPrecautionByGrid(map.get("unreformCount"), map.get("alreadyReformCount1"), map.get("reformingCount"),
                map.get("alreadyReformCount1"), map.get("refuseReformCount"), updateTimeStart, updateTimeEnd, codeList);
        if (dangerAnalysis == null)
            dangerAnalysis = new DangerAnalysis();
        dangerAnalysis.setDepartmentCode(departmentTreeBean == null ? "776B361BFFAC4F00BBF459CD1303A8B2" : departmentTreeBean.getDepartmentCode());
        dangerAnalysis.setDepartmentName(departmentTreeBean == null ? "水之眼" : departmentTreeBean.getName());
        if (dangerAnalysis1 != null) {
            computeRate(dangerAnalysis, dangerAnalysis1);
        }
        dangerAnalysisList.add(dangerAnalysis);
    }

    private void generateDangerAnalysis1(List<DangerAnalysis> dangerAnalysisList, SessionFactory factory, DepartmentTreeBean departmentTreeBean, Date updateTimeStart, Date updateTimeEnd) {
        //查询当前部门下的所有网格（包括网格和部门）,不包含自己本身
        List<String> codeList = new ArrayList<>();
        if (departmentTreeBean != null) {
            codeList = nodeService.getChildCodeList(departmentTreeBean.getDepartmentCode());
            if (codeList == null)
                codeList = new ArrayList<>();
            codeList.add(departmentTreeBean.getDepartmentCode());
        }
        // 根据二级分类分类查询数据
        Map queryMap = new HashMap();
        queryMap.putAll(dictQueryMap);
        queryMap.put("updateTimeStart", updateTimeStart);
        queryMap.put("updateTimeEnd", updateTimeEnd);
        queryMap.put("codeList", codeList);
        DangerAnalysis dangerAnalysis = factory.getMapper(DataAnalysisMapper.class).getDangerByGrid(queryMap);

        DangerAnalysis dangerAnalysis1 = factory.getMapper(DataAnalysisMapper.class).queryCountDangerPrecautionByGrid1(updateTimeStart, updateTimeEnd, codeList);

//        DangerAnalysis dangerAnalysis1 = factory.getMapper(DataAnalysisMapper.class).queryCountDangerPrecautionByGrid(this.map.get("unreformCount"), this.map.get("alreadyReformCount1"), this.map.get("reformingCount"),
//                this.map.get("alreadyReformCount1"), this.map.get("refuseReformCount"), updateTimeStart, updateTimeEnd, codeList);
        dangerAnalysis.setDepartmentCode(departmentTreeBean == null ? "776B361BFFAC4F00BBF459CD1303A8B2" : departmentTreeBean.getDepartmentCode());
        dangerAnalysis.setDepartmentName(departmentTreeBean == null ? "水之眼" : departmentTreeBean.getName());
        if (dangerAnalysis1 != null) {
            computeRate(dangerAnalysis, dangerAnalysis1);
        }
        dangerAnalysisList.add(dangerAnalysis);
    }

    private void computeRate(DangerAnalysis target, DangerAnalysis source) {
        target.setAlreadyReformCount(source.getAlreadyReformCount());
        target.setReformingCount(source.getReformingCount());
        target.setUnreformCount(source.getUnreformCount());
        //计算整改率
        Integer total = source.getUnreformCount() + source.getReformingCount() + source.getAlreadyReformCount();
        BigDecimal totalValue = new BigDecimal(total);
        BigDecimal rate = total == 0 ? new BigDecimal(0) : new BigDecimal(source.getAlreadyReformCount()).divide(totalValue, 4, BigDecimal.ROUND_HALF_UP);
        target.setReformRate(rate);
    }

//    public MessageBean<List<DangerAnalysis>> queryCountDangerByCorp(Date updateTimeStart, Date updateTimeEnd,String code) {
//        MessageBean<List<DangerAnalysis>> msg=new MessageBean<>();
//        try(SessionFactory factory=new SessionFactory()){
//            if (null==map||map.isEmpty()){
//                setMap();
//            }
//            if (null==map||map.isEmpty()){
//                msg.setCode(-1);
//                msg.setDescription("统计项基础数据为空，无法进行统计");
//                return msg;
//            }
//            List<DangerAnalysis> analysisList=new ArrayList<>();
//            if (StringUtils.isEmpty(code)){
//
//                List<CorpBean> corpBeanList=corpManagementService.corpBeanList();
//                for(CorpBean bean:corpBeanList){
//                    if (null!=bean.getLongitude()){
//                        List<DepartmentTreeBean> treeBeanList= (List<DepartmentTreeBean>) util.depttree(bean.getCorpCode(),1).getData();
//                        List<String> codeList=new ArrayList<>();
//                        if(null!=treeBeanList&&treeBeanList.size()>0){
//                            codeList.addAll(treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList()));
//                            DangerAnalysis dangerAnalysis1=factory.getMapper(DataAnalysisMapper.class).queryCountDanger(map.get("nomarlDangerCount"),map.get("importantDangerCont"),map.get("managerDangetCount"),
//                                    map.get("deviceDangerCount"),map.get("meterialDangerCount"),map.get("personDangerCount"),map.get("goodsDangerCount"),
//                                    map.get("enviropmentDangerCount"),updateTimeStart,updateTimeEnd,codeList);
//                            DangerAnalysis dangerAnalysis2=factory.getMapper(DataAnalysisMapper.class).queryCountDangerPrecaution(map.get("unreformCount"),map.get("alreadyReformCount1"),map.get("reformingCount"),
//                                    map.get("alreadyReformCount1"),map.get("refuseReformCount"),updateTimeStart,updateTimeEnd,codeList);
//                            dangerAnalysis1.setUnreformCount(dangerAnalysis2.getUnreformCount());
//                            dangerAnalysis1.setAlreadyReformCount(dangerAnalysis2.getAlreadyReformCount());
//                            dangerAnalysis1.setReformingCount(dangerAnalysis2.getReformingCount());
//                            dangerAnalysis1.setReformRate(dangerAnalysis2.getReformRate());
//                            dangerAnalysis1.setDepartmentCode(bean.getCorpCode());
//                            dangerAnalysis1.setDepartmentName(bean.getCorpName());
//                            analysisList.add(dangerAnalysis1);
//                        }
//                    }
//                }
//            }else {
//                if (StringUtils.equals("d29fdd2bc8a4474d8b17d7f69c96569e", code)) {
//                    //粤港供水
//                    for (String node : nodeList) {
//                        List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(node, 0).getData();
//                        List<Map> gridNodes = (List<Map>) nodeService.childList(node, 1).getData();
//                        if (null != gridNodes && gridNodes.size() > 0) {
//                            List<String> codeList = new ArrayList<>();
//                            for (Map map : gridNodes) {
//                                codeList.add((String) map.get("code"));
//                            }
//                            DangerAnalysis dangerAnalysis = factory.getMapper(DataAnalysisMapper.class).queryCountDangerByGrid(map.get("nomarlDangerCount"), map.get("importantDangerCont"), map.get("managerDangetCount"),
//                                    map.get("deviceDangerCount"), map.get("meterialDangerCount"), map.get("personDangerCount"), map.get("goodsDangerCount"),
//                                    map.get("enviropmentDangerCount"), updateTimeStart, updateTimeEnd, codeList);
//                            DangerAnalysis dangerAnalysis2 = factory.getMapper(DataAnalysisMapper.class).queryCountDangerPrecautionByGrid(map.get("unreformCount"), map.get("alreadyReformCount1"), map.get("reformingCount"),
//                                    map.get("alreadyReformCount1"), map.get("refuseReformCount"), updateTimeStart, updateTimeEnd, codeList);
//                            dangerAnalysis.setDepartmentId(treeBeanList.get(0).getId().toString());
//                            dangerAnalysis.setDepartmentCode(treeBeanList.get(0).getDepartmentCode());
//                            dangerAnalysis.setDepartmentName(treeBeanList.get(0).getName());
//                            dangerAnalysis.setUnreformCount(dangerAnalysis2.getUnreformCount());
//                            dangerAnalysis.setAlreadyReformCount(dangerAnalysis2.getAlreadyReformCount());
//                            dangerAnalysis.setReformingCount(dangerAnalysis2.getReformingCount());
//                            dangerAnalysis.setReformRate(dangerAnalysis2.getReformRate());
//                            analysisList.add(dangerAnalysis);
//                        }
//                    }
//                }
//            }
//            msg.setCode(BusinessCode.SUCCESS.getCode());
//            msg.setDescription(BusinessCode.SUCCESS.getDescription());
//            msg.setData(analysisList);
//            return msg;
//        }catch (Exception e){
//            logger.error(e.getMessage(),e);
//            msg.setCode(BusinessCode.EXCEPTION.getCode());
//            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
//            return msg;
//        }
//    }

    @Override
    public MessageBean<List<LocalHazarsSourceAnalysis>> queryCountRiskHazardSource(Date updateTimeStart, Date
            updateTimeEnd, String code) {
        MessageBean<List<LocalHazarsSourceAnalysis>> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            if (null == map || map.isEmpty()) {
                setMap();
            }
            if (null == map || map.isEmpty()) {
                msg.setCode(-1);
                msg.setDescription("统计项基础数据为空，无法进行统计");
                return msg;
            }
            List<LocalHazarsSourceAnalysis> analysisList = new ArrayList<>();
            if (StringUtils.isEmpty(code)) {
                //查询所有数据
                generateLocalHazarsSourceAnalysis(factory, analysisList, null, updateTimeStart, updateTimeEnd);
            } else {
                List<DepartmentTreeBean> departmentTreeBeanList = (List<DepartmentTreeBean>) util.depttree(code, 0).getData();
                if (departmentTreeBeanList != null && departmentTreeBeanList.size() > 1) {
                    //第一个是自己本身，不要自己本身的数据
                    for (int i = 1; i < departmentTreeBeanList.size(); i++) {
                        DepartmentTreeBean departmentTreeBean = departmentTreeBeanList.get(i);
                        generateLocalHazarsSourceAnalysis(factory, analysisList, departmentTreeBean, updateTimeStart, updateTimeEnd);
                    }
                } else {
                    //不存在下级部门
                    if (departmentTreeBeanList.size() > 0) {
                        generateLocalHazarsSourceAnalysis(factory, analysisList, departmentTreeBeanList.get(0), updateTimeStart, updateTimeEnd);
                    }
                    if (null != analysisList && analysisList.size() > 0)
                        analysisList.get(0).setExistChild(0);
                }
            }

            msg.setData(analysisList);
            msg.setCode(BusinessCode.SUCCESS.getCode());
            msg.setDescription(BusinessCode.SUCCESS.getDescription());
            return msg;
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }

    private void generateLocalHazarsSourceAnalysis(SessionFactory
                                                           factory, List<LocalHazarsSourceAnalysis> analysisList, DepartmentTreeBean departmentTreeBean, Date
                                                           updateTimeStart, Date updateTimeEnd) {
        //不包括本身的code
        List<String> codeList = new ArrayList<>();
        if (null != departmentTreeBean) {
            codeList = nodeService.getChildCodeList(departmentTreeBean.getDepartmentCode());
            if (codeList == null || codeList.size() <= 0) {
                codeList = nodeService.getChildCodeList("776B361BFFAC4F00BBF459CD1303A8B2");
                if (!codeList.contains("776B361BFFAC4F00BBF459CD1303A8B2"))
                    codeList.add("776B361BFFAC4F00BBF459CD1303A8B2");
            } else {
                codeList.add(departmentTreeBean.getDepartmentCode());
            }
        } else {
            codeList = nodeService.getChildCodeList("776B361BFFAC4F00BBF459CD1303A8B2");
            if (!codeList.contains("776B361BFFAC4F00BBF459CD1303A8B2"))
                codeList.add("776B361BFFAC4F00BBF459CD1303A8B2");
        }
        //查风险统计
        LocalHazarsSourceAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).queryCountRiskHazardSourceByGrid(updateTimeStart, updateTimeEnd, codeList);
        //查重大危险源数量
        LocalHazarsSourceAnalysis analysis1 = factory.getMapper(DataAnalysisMapper.class).queryCountHazradByGrid(map.get("majorHazardSource"), updateTimeStart, updateTimeEnd, codeList);
        if (analysis == null)
            analysis = new LocalHazarsSourceAnalysis();
        analysis.setDepartmentCode(departmentTreeBean == null ? "776B361BFFAC4F00BBF459CD1303A8B2" : departmentTreeBean.getDepartmentCode());
        analysis.setDepartmentName(departmentTreeBean == null ? "水之眼" : departmentTreeBean.getName());
        if (analysis1 != null)
            analysis.setMajorHazardSource(analysis1.getMajorHazardSource());
        analysisList.add(analysis);
    }

//    public MessageBean<List<LocalHazarsSourceAnalysis>> queryCountRiskHazardSourceByCorp(Date updateTimeStart, Date updateTimeEnd, String code) {
//        MessageBean<List<LocalHazarsSourceAnalysis>> msg=new MessageBean<>();
//        try(SessionFactory factory=new SessionFactory()){
//            if (null==map||map.isEmpty()){
//                setMap();
//            }
//            if (null==map||map.isEmpty()){
//                msg.setCode(-1);
//                msg.setDescription("统计项基础数据为空，无法进行统计");
//                return msg;
//            }
//            List<LocalHazarsSourceAnalysis> analysisList=new ArrayList<>();
//            if (StringUtils.isEmpty(code)){
//                List<CorpBean> corpBeanList=corpManagementService.corpBeanList();
//                for(CorpBean bean:corpBeanList){
//                    if (null!=bean.getLongitude()){
//                        List<DepartmentTreeBean> treeBeanList= (List<DepartmentTreeBean>) util.depttree(bean.getCorpCode(),1).getData();
//                        List<String> codeList=new ArrayList<>();
//                        if(null!=treeBeanList&&treeBeanList.size()>0){
//                            codeList.addAll(treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList()));
//                            LocalHazarsSourceAnalysis analysis=factory.getMapper(DataAnalysisMapper.class).queryCountRiskHazardSource(updateTimeStart,updateTimeEnd,codeList);
//                            LocalHazarsSourceAnalysis analysis1=factory.getMapper(DataAnalysisMapper.class).queryCountHazrad(map.get("majorHazardSource"),updateTimeStart,updateTimeEnd,codeList);
//                            analysis.setDepartmentName(bean.getCorpName());
//                            analysis.setDepartmentCode(bean.getCorpCode());
//                            if (null!=analysis1){
//                                analysis.setMajorHazardSource(analysis1.getMajorHazardSource());
//                            }
//                            analysisList.add(analysis);
//                        }
//                    }
//                }
//            }else{
//                //粤港供水专用
//                if(StringUtils.equals("d29fdd2bc8a4474d8b17d7f69c96569e",code)){
//                    for(String node:nodeList){
//                        List<String> idList=new ArrayList<>();
//                        List<DepartmentTreeBean> treeBeanList= (List<DepartmentTreeBean>) util.depttree(node,0).getData();
//                        SourceQueryBean queryBean=new SourceQueryBean();
//                        queryBean.setCorpCode("d29fdd2bc8a4474d8b17d7f69c96569e");
//                        queryBean.setGridCode(node);
//                        DataBean<LocalHazardSource> data= (DataBean<LocalHazardSource>) sourceService.childAll(queryBean).getData();
//                        List<LocalHazardSource> localHazardSources=data.getList();
//                        LocalHazarsSourceAnalysis sourceAnalysis=new LocalHazarsSourceAnalysis();
//                        if (null!=localHazardSources&&localHazardSources.size()>0)
//                            idList.addAll(localHazardSources.stream().map(LocalHazardSource::getId).collect(Collectors.toList()));
//                        if (null!=idList&&idList.size()>0){
//                            sourceAnalysis=factory.getMapper(DataAnalysisMapper.class).queryCountRiskHazardSource(updateTimeStart,updateTimeEnd,idList);
//                            LocalHazarsSourceAnalysis sourceAnalysis1=factory.getMapper(DataAnalysisMapper.class).queryCountHazrad(map.get("majorHazardSource"),updateTimeStart,updateTimeEnd,idList);
//                            if (null!=sourceAnalysis1){
//                                sourceAnalysis.setMajorHazardSource(sourceAnalysis1.getMajorHazardSource());
//                            }
//                        }
//                        sourceAnalysis.setDepartmentCode(node);
//                        sourceAnalysis.setDepartmentName(treeBeanList.get(0).getName());
//                        analysisList.add(sourceAnalysis);
//                    }
//                }
//            }
//            msg.setCode(BusinessCode.SUCCESS.getCode());
//            msg.setDescription(BusinessCode.SUCCESS.getDescription());
//            msg.setData(analysisList);
//            return msg;
//        }catch (Exception e){
//            logger.error(e.getMessage(),e);
//            msg.setCode(BusinessCode.EXCEPTION.getCode());
//            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
//            return msg;
//        }
//    }

    @Override
    public MessageBean<LocalHazarsSourceAnalysis> countRiskHazardSource(Date updateTimeStart, Date
            updateTimeEnd, String code) {
        MessageBean<LocalHazarsSourceAnalysis> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            if (null == map || map.isEmpty()) {
                setMap();
            }
            if (null == map || map.isEmpty()) {
                msg.setCode(-1);
                msg.setDescription("统计项基础数据为空，无法进行统计");
                return msg;
            }
            List<LocalHazarsSourceAnalysis> analysisList = new ArrayList<>();
            if (StringUtils.isEmpty(code)) {
                generateLocalHazarsSourceAnalysis(factory, analysisList, null, updateTimeStart, updateTimeEnd);
            } else {
                List<DepartmentTreeBean> departmentTreeBeanList = (List<DepartmentTreeBean>) util.depttree(code, 0).getData();
                if (null != departmentTreeBeanList && departmentTreeBeanList.size() > 0) {
                    generateLocalHazarsSourceAnalysis(factory, analysisList, departmentTreeBeanList.get(0), updateTimeStart, updateTimeEnd);
                }
            }
            if (analysisList != null && analysisList.size() > 0)
                msg.setData(analysisList.get(0));
            msg.setCode(BusinessCode.SUCCESS.getCode());
            msg.setDescription(BusinessCode.SUCCESS.getDescription());
            return msg;
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }

    @Override
    public MessageBean<List<UserTaskAnalysis>> queryCountUserTask(Date updateTimeStart, Date updateTimeEnd, String
            code) {
        MessageBean<List<UserTaskAnalysis>> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            if (null == map || map.isEmpty()) {
                setMap();
            }
            if (null == map || map.isEmpty()) {
                msg.setCode(-1);
                msg.setDescription("统计项基础数据为空，无法进行统计");
                return msg;
            }
            if (StringUtils.isEmpty(code)) {
                //查询片区
                List<District> districtList = factory.getMapper(DistrictMapper.class).queryAllDistrict(null, null);
                List<UserTaskAnalysis> analysisList = new ArrayList<>();
                for (District district : districtList) {
                    List<DistrictCorpRelation> relationList = factory.getMapper(DistrictMapper.class).queryDistrictCorp(district.getCode(), null, null);
                    List<String> codeList = new ArrayList<>();
                    for (DistrictCorpRelation relation : relationList) {
                        List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(relation.getCorpCode(), 1).getData();
                        if (null != treeBeanList && treeBeanList.size() > 0)
                            codeList.addAll(treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList()));
                    }
                    if (null != codeList && codeList.size() > 0) {
                        UserTaskAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).queryCountUserTask(updateTimeStart, updateTimeEnd, codeList);
                        analysis.setDepartmentName(district.getName());
                        analysis.setDepartmentCode(district.getCode());
                        analysisList.add(analysis);
                    }
                }
                msg.setCode(BusinessCode.SUCCESS.getCode());
                msg.setData(analysisList);
                msg.setDescription(BusinessCode.SUCCESS.getDescription());
                return msg;
            } else {
                //指定某个片区下的各水司的任务完成情况
                District district = factory.getMapper(DistrictMapper.class).queryOneDistrictByCode(code);
                List<UserTaskAnalysis> analysisList = new ArrayList<>();
                if (null != district) {
                    List<DistrictCorpRelation> relationList = factory.getMapper(DistrictMapper.class).queryDistrictCorp(code, null, null);
                    for (DistrictCorpRelation relation : relationList) {
                        List<String> codeList = new ArrayList<>();
                        List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(code, 1).getData();
                        if (null != treeBeanList && treeBeanList.size() > 0)
                            codeList = treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList());
                        UserTaskAnalysis taskAnalysis = factory.getMapper(DataAnalysisMapper.class).queryCountUserTask(updateTimeStart, updateTimeEnd,
                                codeList == null || codeList.size() <= 0 ? null : codeList);
                        taskAnalysis.setDepartmentCode(treeBeanList.get(0).getDepartmentCode());
                        taskAnalysis.setDepartmentName(treeBeanList.get(0).getName());
                        analysisList.add(taskAnalysis);
                    }
                } else {
                    if (StringUtils.equals("d29fdd2bc8a4474d8b17d7f69c96569e", code)) {
                        //粤港，查下属五个泵站
                        for (String node : nodeList) {
                            List<String> codeList = new ArrayList<>();
                            List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(node, 1).getData();
                            if (null != treeBeanList && treeBeanList.size() > 0)
                                codeList = treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList());
                            UserTaskAnalysis taskAnalysis = factory.getMapper(DataAnalysisMapper.class).queryCountUserTaskByGrid(updateTimeStart, updateTimeEnd,
                                    codeList == null || codeList.size() <= 0 ? null : codeList);
                            taskAnalysis.setDepartmentCode(treeBeanList.get(0).getDepartmentCode());
                            taskAnalysis.setDepartmentName(treeBeanList.get(0).getName());
                            analysisList.add(taskAnalysis);
                        }
                    }
                }

                msg.setCode(BusinessCode.SUCCESS.getCode());
                msg.setData(analysisList);
                msg.setDescription(BusinessCode.SUCCESS.getDescription());
                return msg;
            }
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }

    @Override
    public MessageBean<List<UserTaskAnalysis>> queryCountUserTaskByCorp(Date updateTimeStart, Date
            updateTimeEnd, String code) {
        MessageBean<List<UserTaskAnalysis>> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            if (null == map || map.isEmpty()) {
                setMap();
            }
            if (null == map || map.isEmpty()) {
                msg.setCode(-1);
                msg.setDescription("统计项基础数据为空，无法进行统计");
                return msg;
            }
            List<UserTaskAnalysis> analysisList = new ArrayList<>();
            if (StringUtils.isEmpty(code)) {
                List<CorpBean> corpBeanList = corpManagementService.corpBeanList();
                for (CorpBean bean : corpBeanList) {
                    if (null != bean.getLongitude()) {
                        List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(bean.getCorpCode(), 1).getData();
                        List<String> codeList = new ArrayList<>();
                        if (null != treeBeanList && treeBeanList.size() > 0) {
                            codeList.addAll(treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList()));
                            UserTaskAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).queryCountUserTask(updateTimeStart, updateTimeEnd, codeList);
                            analysis.setDepartmentName(bean.getCorpName());
                            analysis.setDepartmentCode(bean.getCorpCode());
                            analysisList.add(analysis);
                        }
                    }
                }
            } else {
                if (StringUtils.equals("d29fdd2bc8a4474d8b17d7f69c96569e", code)) {
                    //粤港，查下属五个泵站
                    for (String node : nodeList) {
                        List<String> codeList = new ArrayList<>();
                        List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(node, 1).getData();
                        if (null != treeBeanList && treeBeanList.size() > 0)
                            codeList = treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList());
                        UserTaskAnalysis taskAnalysis = factory.getMapper(DataAnalysisMapper.class).queryCountUserTaskByGrid(updateTimeStart, updateTimeEnd,
                                codeList == null || codeList.size() <= 0 ? null : codeList);
                        taskAnalysis.setDepartmentCode(treeBeanList.get(0).getDepartmentCode());
                        taskAnalysis.setDepartmentName(treeBeanList.get(0).getName());
                        analysisList.add(taskAnalysis);
                    }
                }
            }
            msg.setCode(BusinessCode.SUCCESS.getCode());
            msg.setDescription(BusinessCode.SUCCESS.getDescription());
            msg.setData(analysisList);
            return msg;
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }

    @Override
    public MessageBean<UserTaskAnalysis> countUserTask(Date updateTimeStart, Date updateTimeEnd, String code) {
        MessageBean<UserTaskAnalysis> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            if (null == map || map.isEmpty()) {
                setMap();
            }
            if (null == map || map.isEmpty()) {
                msg.setCode(-1);
                msg.setDescription("统计项基础数据为空，无法进行统计");
                return msg;
            }
            if (StringUtils.isEmpty(code)) {
                UserTaskAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).queryCountUserTask(updateTimeStart, updateTimeEnd, null);
                msg.setCode(BusinessCode.SUCCESS.getCode());
                msg.setDescription(BusinessCode.SUCCESS.getDescription());
                msg.setData(analysis);
                return msg;
            } else {
                //统计某个区域的
                District district = factory.getMapper(DistrictMapper.class).queryOneDistrictByCode(code);
                CorpBean corpBean = factory.getMapper(CorpManagementMapper.class).get(code);
                if (null == district && corpBean == null) {
                    msg.setCode(BusinessCode.SUCCESS.getCode());
                    msg.setDescription(BusinessCode.SUCCESS.getDescription());
                    return msg;
                }
                if (null != district) {
                    List<DistrictCorpRelation> relationList = factory.getMapper(DistrictMapper.class).queryDistrictCorp(code, null, null);
                    List<String> codeList = new ArrayList<>();
                    for (DistrictCorpRelation relation : relationList) {
                        List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(relation.getCorpCode(), 1).getData();
                        if (null != treeBeanList && treeBeanList.size() > 0)
                            codeList.addAll(treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList()));
                    }
                    if (null != codeList && codeList.size() > 0) {
                        UserTaskAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).queryCountUserTask(updateTimeStart, updateTimeEnd, codeList);
                        analysis.setDepartmentName(district.getName());
                        analysis.setDepartmentCode(district.getCode());
                        msg.setData(analysis);
                    }
                    msg.setCode(BusinessCode.SUCCESS.getCode());
                    msg.setDescription(BusinessCode.SUCCESS.getDescription());
                    return msg;
                } else {
                    List<String> codeList = new ArrayList<>();
                    List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(code, 1).getData();
                    if (null != treeBeanList && treeBeanList.size() > 0)
                        codeList.addAll(treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList()));
                    if (null != codeList && codeList.size() > 0) {
                        UserTaskAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).queryCountUserTask(updateTimeStart, updateTimeEnd, codeList);
                        analysis.setDepartmentName(treeBeanList.get(0).getName());
                        analysis.setDepartmentCode(treeBeanList.get(0).getDepartmentCode());
                        msg.setData(analysis);
                    }
                    msg.setCode(BusinessCode.SUCCESS.getCode());
                    msg.setDescription(BusinessCode.SUCCESS.getDescription());
                    return msg;
                }

            }
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }

    @Override
    public MessageBean<List<CheckRecordAnalysis>> queryCountCheckRecord(Date updateTimeStart, Date
            updateTimeEnd, String code) {
        MessageBean<List<CheckRecordAnalysis>> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            if (null == map || map.isEmpty()) {
                setMap();
            }
            if (null == map || map.isEmpty()) {
                msg.setCode(-1);
                msg.setDescription("统计项基础数据为空，无法进行统计");
                return msg;
            }
            if (StringUtils.isEmpty(code)) {
                //查询片区
                List<District> districtList = factory.getMapper(DistrictMapper.class).queryAllDistrict(null, null);
                List<CheckRecordAnalysis> analysisList = new ArrayList<>();
                for (District district : districtList) {
                    List<DistrictCorpRelation> relationList = factory.getMapper(DistrictMapper.class).queryDistrictCorp(district.getCode(), null, null);
                    List<String> codeList = new ArrayList<>();
                    for (DistrictCorpRelation relation : relationList) {
                        List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(relation.getCorpCode(), 1).getData();
                        if (null != treeBeanList && treeBeanList.size() > 0)
                            codeList.addAll(treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList()));
                    }
                    if (null != codeList && codeList.size() > 0) {
                        CheckRecordAnalysis checkRecordAnalysis = factory.getMapper(DataAnalysisMapper.class).queryCountCheckRecord(map.get("groupClass"),
                                map.get("plateClass"), map.get("departmnetClass"), map.get("departmnetClass"), updateTimeStart, updateTimeEnd, codeList);
                        checkRecordAnalysis.setDepartmentCode(district.getCode());
                        checkRecordAnalysis.setDepartmentName(district.getName());
                        analysisList.add(checkRecordAnalysis);
                    }
                }
                msg.setCode(BusinessCode.SUCCESS.getCode());
                msg.setDescription(BusinessCode.SUCCESS.getDescription());
                msg.setData(analysisList);
                return msg;
            } else {
                //查询某个片区下水司的检查任务统计情况
                District district = factory.getMapper(DistrictMapper.class).queryOneDistrictByCode(code);
                List<CheckRecordAnalysis> analysisList = new ArrayList<>();
                if (null != district) {
                    List<DistrictCorpRelation> relationList = factory.getMapper(DistrictMapper.class).queryDistrictCorp(code, null, null);
                    for (DistrictCorpRelation relation : relationList) {
                        List<String> codeList = new ArrayList<>();
                        List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(relation.getCorpCode(), 0).getData();
                        codeList.add(relation.getCorpCode());
                        if (null != codeList && codeList.size() > 0) {
                            CheckRecordAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).queryCountCheckRecord(map.get("groupClass"),
                                    map.get("plateClass"), map.get("departmnetClass"), map.get("departmnetClass"), updateTimeStart, updateTimeEnd, codeList);
                            analysis.setDepartmentName(treeBeanList.get(0).getName());
                            analysis.setDepartmentCode(treeBeanList.get(0).getDepartmentCode());
                            analysisList.add(analysis);
                        }
                    }
                } else {
                    //针对粤港供水
                    if (StringUtils.equals("d29fdd2bc8a4474d8b17d7f69c96569e", code)) {
                        //查询五大泵站
                        for (String node : nodeList) {
                            List<String> codeList = new ArrayList<>();
                            List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(node, 1).getData();
                            List<Map> list = (List<Map>) nodeService.childList(node, 1).getData();
                            if (null != list && list.size() > 0) {
                                for (Map map : list) {
                                    if (StringUtils.isNotEmpty((String) map.get("code"))) {
                                        codeList.add((String) map.get("code"));
                                    }
                                }
                            }
                            if (null != codeList && codeList.size() > 0) {
                                CheckRecordAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).queryCountCheckRecord(map.get("groupClass"),
                                        map.get("plateClass"), map.get("departmnetClass"), map.get("departmnetClass"), updateTimeStart, updateTimeEnd, codeList);
                                analysis.setDepartmentName(treeBeanList.get(0).getName());
                                analysis.setDepartmentCode(treeBeanList.get(0).getDepartmentCode());
                                analysisList.add(analysis);
                            }
                        }
                    }
                }
                msg.setCode(BusinessCode.SUCCESS.getCode());
                msg.setDescription(BusinessCode.SUCCESS.getDescription());
                msg.setData(analysisList);
                return msg;
            }
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }

    @Override
    public MessageBean<List<CheckRecordAnalysis>> queryCountCheckRecordByCorp(Date updateTimeStart, Date
            updateTimeEnd, String code) {
        MessageBean<List<CheckRecordAnalysis>> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            if (null == map || map.isEmpty()) {
                setMap();
            }
            if (null == map || map.isEmpty()) {
                msg.setCode(-1);
                msg.setDescription("统计项基础数据为空，无法进行统计");
                return msg;
            }
            List<CheckRecordAnalysis> analysisList = new ArrayList<>();
            if (StringUtils.isEmpty(code)) {
                List<CorpBean> corpBeanList = corpManagementService.corpBeanList();
                for (CorpBean bean : corpBeanList) {
                    if (null != bean.getLongitude()) {
                        List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(bean.getCorpCode(), 1).getData();
                        List<String> codeList = new ArrayList<>();
                        if (null != treeBeanList && treeBeanList.size() > 0) {
                            codeList.addAll(treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList()));
                            CheckRecordAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).queryCountCheckRecord(map.get("groupClass"),
                                    map.get("plateClass"), map.get("departmnetClass"), map.get("departmnetClass"), updateTimeStart, updateTimeEnd, codeList);
                            analysis.setDepartmentName(bean.getCorpName());
                            analysis.setDepartmentCode(bean.getCorpCode());
                            analysisList.add(analysis);
                        }
                    }
                }
            } else {
                //粤海供水
                //针对粤港供水
                if (StringUtils.equals("d29fdd2bc8a4474d8b17d7f69c96569e", code)) {
                    //查询五大泵站
                    for (String node : nodeList) {
                        List<String> codeList = new ArrayList<>();
                        List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(node, 1).getData();
                        List<Map> list = (List<Map>) nodeService.childList(node, 1).getData();
                        if (null != list && list.size() > 0) {
                            for (Map map : list) {
                                if (StringUtils.isNotEmpty((String) map.get("code"))) {
                                    codeList.add((String) map.get("code"));
                                }
                            }
                        }
                        if (null != codeList && codeList.size() > 0) {
                            CheckRecordAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).queryCountCheckRecord(map.get("groupClass"),
                                    map.get("plateClass"), map.get("departmnetClass"), map.get("departmnetClass"), updateTimeStart, updateTimeEnd, codeList);
                            analysis.setDepartmentName(treeBeanList.get(0).getName());
                            analysis.setDepartmentCode(treeBeanList.get(0).getDepartmentCode());
                            analysisList.add(analysis);
                        }
                    }
                }
            }

            msg.setCode(BusinessCode.SUCCESS.getCode());
            msg.setDescription(BusinessCode.SUCCESS.getDescription());
            msg.setData(analysisList);
            return msg;
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }

    @Override
    public MessageBean<CheckRecordAnalysis> countCheckRecord(Date updateTimeStart, Date updateTimeEnd, String code) {
        MessageBean<CheckRecordAnalysis> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            if (null == map || map.isEmpty()) {
                setMap();
            }
            if (null == map || map.isEmpty()) {
                msg.setCode(-1);
                msg.setDescription("统计项基础数据为空，无法进行统计");
                return msg;
            }
            if (StringUtils.isEmpty(code)) {
                //查询片区
                CheckRecordAnalysis checkRecordAnalysis = factory.getMapper(DataAnalysisMapper.class).queryCountCheckRecord(map.get("groupClass"),
                        map.get("plateClass"), map.get("departmnetClass"), map.get("departmnetClass"), updateTimeStart, updateTimeEnd, null);
                msg.setCode(BusinessCode.SUCCESS.getCode());
                msg.setDescription(BusinessCode.SUCCESS.getDescription());
                msg.setData(checkRecordAnalysis);
                return msg;
            } else {
                //查询某个片区下水司的检查任务统计情况
                District district = factory.getMapper(DistrictMapper.class).queryOneDistrictByCode(code);
                CorpBean corpBean = factory.getMapper(CorpManagementMapper.class).get(code);
                if (null == district && null == corpBean) {
                    msg.setCode(BusinessCode.SUCCESS.getCode());
                    msg.setDescription(BusinessCode.SUCCESS.getDescription());
                    return msg;
                }
                if (null != district) {
                    List<DistrictCorpRelation> relationList = factory.getMapper(DistrictMapper.class).queryDistrictCorp(code, null, null);
                    List<String> codeList = new ArrayList<>();
                    for (DistrictCorpRelation relation : relationList) {
                        List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(relation.getCorpCode(), 1).getData();
                        if (null != treeBeanList && treeBeanList.size() > 0)
                            codeList.addAll(treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList()));
                    }
                    if (null != codeList && codeList.size() > 0) {
                        CheckRecordAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).queryCountCheckRecord(map.get("groupClass"),
                                map.get("plateClass"), map.get("departmnetClass"), map.get("departmnetClass"), updateTimeStart, updateTimeEnd, codeList);
                        analysis.setDepartmentName(district.getName());
                        analysis.setDepartmentCode(district.getCode());
                        msg.setData(analysis);
                    }
                    msg.setCode(BusinessCode.SUCCESS.getCode());
                    msg.setDescription(BusinessCode.SUCCESS.getDescription());
                    return msg;
                } else {
                    List<String> codeList = new ArrayList<>();
                    List<DepartmentTreeBean> treeBeanList = (List<DepartmentTreeBean>) util.depttree(code, 1).getData();
                    if (null != treeBeanList && treeBeanList.size() > 0)
                        codeList.addAll(treeBeanList.stream().map(DepartmentTreeBean::getDepartmentCode).collect(Collectors.toList()));
                    if (null != codeList && codeList.size() > 0) {
                        CheckRecordAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).queryCountCheckRecord(map.get("groupClass"),
                                map.get("plateClass"), map.get("departmnetClass"), map.get("departmnetClass"), updateTimeStart, updateTimeEnd, codeList);
                        analysis.setDepartmentName(treeBeanList.get(0).getName());
                        analysis.setDepartmentCode(treeBeanList.get(0).getDepartmentCode());
                        msg.setData(analysis);
                    }
                    msg.setCode(BusinessCode.SUCCESS.getCode());
                    msg.setDescription(BusinessCode.SUCCESS.getDescription());
                    return msg;
                }

            }
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        setMap();
    }

    @Override
    public Map<String, String> getAnalysisDateMap() {
        return map;
    }

    @Override
    public MessageBean<List<AccidentBulletinAnalysis>> getAccidentAnalysis(String corpCode, String
            startTime, String endTime) {
        MessageBean<List<AccidentBulletinAnalysis>> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            List<AccidentBulletinAnalysis> list = new ArrayList<>();
            if (null == accidentTypeMap || accidentTypeMap.isEmpty()) {
                setAccidentTypeMap();
            }
            if (null == accidentTypeMap || accidentTypeMap.isEmpty()) {
                msg.setCode(-1);
                msg.setDescription("统计项基础数据为空，无法进行统计");
                return msg;
            }
            //未传入code时，查询所有
            if (StringUtils.isEmpty(corpCode)) {
                accidentAnalysis(list, factory, null, startTime, endTime);
            } else {
                //查询指定code的直接下属部门
                List<DepartmentTreeBean> departmentTreeBeanList = (List<DepartmentTreeBean>) util.depttree(corpCode, 0).getData();
                if (null != departmentTreeBeanList && departmentTreeBeanList.size() > 1) {
                    for (int i = 1; i < departmentTreeBeanList.size(); i++) {
                        DepartmentTreeBean departmentTreeBean = departmentTreeBeanList.get(i);
                        accidentAnalysis(list, factory, departmentTreeBean, startTime, endTime);
                    }
                } else {
                    //没有下级部门，直接返回当前部门的数据
                    if (departmentTreeBeanList.size() == 1) {
                        accidentAnalysis(list, factory, departmentTreeBeanList.get(0), startTime, endTime);
                    }
                    if (null != list && list.size() > 0) {
                        for (AccidentBulletinAnalysis bean : list) {
                            bean.setExistChild(0);
                        }
                    }
                }
            }
            msg.setCode(BusinessCode.SUCCESS.getCode());
            msg.setDescription("事故类型统计成功");
            msg.setData(list);
            return msg;
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }

    @Override
    public MessageBean<Map> homePageAnalysis(StaffBean user, String corpCode, Date startTime, Date endTime) {
        MessageBean<Map> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Map map = new HashMap();
            //设置统计开始、结束时间
            if (null == startTime) {
                Calendar calendar = Calendar.getInstance();
                int year = calendar.get(Calendar.YEAR);
                int month = calendar.get(Calendar.MONTH);
                calendar.set(year, month, 1, 0, 0, 0);
                startTime = calendar.getTime();
                startTime = sdf.parse(sdf.format(startTime));
            }
            if (null == endTime) {
                Calendar calendar = Calendar.getInstance();
                int year = calendar.get(Calendar.YEAR);
                int month = calendar.get(Calendar.MONTH);
                calendar.set(year, month + 1, 1, 0, 0, 0);
                endTime = calendar.getTime();
                endTime = sdf.parse(sdf.format(endTime));
            }
            // 2022/2/16，隐患统计改成全年
            Calendar calendar = Calendar.getInstance();
            int year = calendar.get(Calendar.YEAR);
            calendar.set(year, 0, 1, 0, 0, 0);
            Date dangerStartTimeTime = calendar.getTime();
            calendar.add(Calendar.YEAR, 1);
            Date dangerEndTimeTime = calendar.getTime();
            String deptCode = "('"+corpCode+"')";
            String deptCodes =util.getDeptCodes(corpCode);
            HiddenDangerMapper mapper = factory.getMapper(HiddenDangerMapper.class);
            // 获取满足条件的所有隐患数据
            // TODO: 2021/12/31
            List<HiddenDangerDiscovery> list = mapper.queryDangerListByCorpAndTime(deptCode,corpCode, dangerStartTimeTime, dangerEndTimeTime);
            // 获取满足条件的隐患数量
            Integer dangerTotal = mapper.queryDangerCountByCorpAndTime(deptCode, corpCode, dangerStartTimeTime, dangerEndTimeTime);
            list.forEach(item -> setNames(item));
            // 获取整改完成的隐患
            List<HiddenDangerDiscovery> finished = list.stream().filter(bean -> bean.getState() == 5).collect(Collectors.toList());
            // 获取隐患超期的隐患
            List<HiddenDangerDiscovery> delay = list.stream().filter(bean -> null != bean.getIsDelay() && bean.getIsDelay() == 2).collect(Collectors.toList());
            // 查询危险作业票数量
            Integer operationCount = factory.getMapper(DataAnalysisMapper.class).queryOperationCountByCorpAndTime(deptCodes, startTime, endTime);
            // 查询安全检查月数量 ppp
            Integer checkMonthCount = factory.getMapper(CheckRecordMapper.class).queryCheckCountByCorpAndTime(deptCode, startTime, endTime);
            // 查询安全检查年数量
            calendar.set(year, 0, 1, 0, 0, 0);
            startTime = calendar.getTime();
            calendar.set(year + 1, 0, 1, 0, 0, 0);
            endTime = calendar.getTime();
            Integer checkYearCount = factory.getMapper(CheckRecordMapper.class).queryCheckCountByCorpAndTime(deptCode, startTime, endTime);
            map.put("dangerTotal", dangerTotal);
            map.put("dangerFinished", finished.size());
            map.put("dangerDelay", delay.size());
            map.put("delayList", delay);
            map.put("checkMonthCount", checkMonthCount);
            map.put("checkYearCount", checkYearCount);
            map.put("operationCount", operationCount);
            msg.setCode(BusinessCode.SUCCESS.getCode());
            msg.setDescription("获取首页工作台隐患统计成功");
            msg.setData(map);
            factory.close();
            return msg;
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription("查询失败");
            return msg;
        }

    }

    @Override
    public MessageBean<DangerAnalysis> getCountAnalysisDanger(Date updateTimeStart, Date updateTimeEnd, String code) {
        MessageBean<DangerAnalysis> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            if (null ==dictQueryMap || dictQueryMap.isEmpty()) {
                getTable();
            }
            List<DangerAnalysis> dangerAnalysisList = new ArrayList<>();
            //先获取各个状态的id
            if (StringUtils.isEmpty(code)) {
                //查询所有数据
                generateDangerAnalysis1(dangerAnalysisList, factory, null, updateTimeStart, updateTimeEnd);
            } else {
                //查询指定code的直接下属部门
                List<DepartmentTreeBean> departmentTreeBeanList = (List<DepartmentTreeBean>) util.depttree(code, 0).getData();
                //第一条数据就是当前部门的数据
                if (departmentTreeBeanList != null && departmentTreeBeanList.size() > 0) {
                    generateDangerAnalysis1(dangerAnalysisList, factory, departmentTreeBeanList.get(0), updateTimeStart, updateTimeEnd);
                }
            }
            msg.setData(dangerAnalysisList == null || dangerAnalysisList.size() <= 0 ? null : dangerAnalysisList.get(0));
            return msg;
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }

    @Override
    public MessageBean<List> getTable() {
        MessageBean<List> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            // 获取所有二级分类
            MessageBean<List<DictType>> datas = dictTypeService.getDictTypesAndDictDatas("二级分类基础管理类");
            MessageBean<List<DictType>> datas1 = dictTypeService.getDictTypesAndDictDatas("二级分类现场管理类");
            Set<String> dicts = new HashSet<>();
            if (datas.getCode() == 0) {
                DictType dictType = datas.getData().get(0);
                List<DictData> dataList = dictType.getDataList();
                dataList.forEach(bean -> {
                    dictNameMap.put(bean.getId(), bean.getDictLabel());
                    dictCodeMap.put(bean.getId(), bean.getDictKey() + bean.getDictValue());
                    dicts.add(bean.getId());
                    dictQueryMap.put(bean.getDictKey() + bean.getDictValue(), bean.getId());
                });
            }
            if (datas1.getCode() == 0) {
                DictType dictType = datas1.getData().get(0);
                List<DictData> dataList = dictType.getDataList();
                dataList.forEach(bean -> {
                    dictNameMap.put(bean.getId(), bean.getDictLabel());
                    dictCodeMap.put(bean.getId(), bean.getDictKey() + bean.getDictValue());
                    dicts.add(bean.getId());
                    dictQueryMap.put(bean.getDictKey() + bean.getDictValue(), bean.getId());
                });
            }
            List<Map> list = new ArrayList<>();
            int other = 0;
            for (String id : dicts) {
                Map map = new HashMap();
                String name = dictNameMap.get(id);
                if (!"其他".equals(name)) {
                    map.put("keyName", dictNameMap.get(id));
                    map.put("keyCode", dictCodeMap.get(id));
                    list.add(map);
                } else if (other == 0) {
                    map.put("keyName", "其他");
                    map.put("keyCode", "other");
                    list.add(map);
                    other++;
                }
            }
            msg.setData(list);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        return msg;
    }

    @Override
    public MessageBean<List<DangerAnalysis>> analysisDanger(Date updateTimeStart, Date updateTimeEnd, String code) {
        MessageBean<List<DangerAnalysis>> msg = new MessageBean<>();
        try (SessionFactory factory = new SessionFactory()) {
            List<DangerAnalysis> dangerAnalysisList = new ArrayList<>();
            if (null ==dictQueryMap || dictQueryMap.isEmpty()) {
                getTable();
            }
            //判断是否传入了片区code
            if (StringUtils.isEmpty(code)) {
                generateDangerAnalysis1(dangerAnalysisList, factory, null, updateTimeStart, updateTimeEnd);
            } else {
                //查询指定code的直接下属部门
                List<DepartmentTreeBean> departmentTreeBeanList = (List<DepartmentTreeBean>) util.depttree(code, 0).getData();
                if (null != departmentTreeBeanList && departmentTreeBeanList.size() > 1) {
                    for (int i = 1; i < departmentTreeBeanList.size(); i++) {
                        DepartmentTreeBean departmentTreeBean = departmentTreeBeanList.get(i);
                        generateDangerAnalysis1(dangerAnalysisList, factory, departmentTreeBean, updateTimeStart, updateTimeEnd);
                    }
                } else {
                    //没有下级部门，直接返回当前部门的数据
                    if (departmentTreeBeanList.size() == 1) {
                        generateDangerAnalysis1(dangerAnalysisList, factory, departmentTreeBeanList.get(0), updateTimeStart, updateTimeEnd);
                    }
                    if (dangerAnalysisList != null) {
                        dangerAnalysisList.get(0).setExistChild(0);
                    }
                }
            }
            msg.setCode(BusinessCode.SUCCESS.getCode());
            msg.setDescription("查询隐患的统计数据成功");
            msg.setData(dangerAnalysisList);
            return msg;
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            logger.error(e.getMessage(),e);
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }


    private void setNames(HiddenDangerDiscovery danger) {
        if (danger != null) {
            SessionFactory factory = new SessionFactory();
            List<HiddenDangerRectification> rectificationList = factory.getMapper(HiddenDangerMapper.class).queryRectificationByDangerRecordId(danger.getId());
            if (null != rectificationList && rectificationList.size() > 0) {
                HiddenDangerRectification rectification = rectificationList.get(0);
                danger.setRectificationId(rectification.getId());
                danger.setRectifier(rectification.getRectifier());
                danger.setDeadline(rectification.getDeadline());
                danger.setRectifierName(rectification.getRectifierName());
                danger.setRectificationResult(rectification.getRectificationResult());
                danger.setReviewerName(rectification.getReviewerName());
                danger.setReviewer(rectification.getReviewer());
                danger.setSolution(rectification.getSolution());
                danger.setReviewTime(rectification.getReviewTime());
                danger.setReviewResult(rectification.getReviewResult());
                danger.setConfirmPerson(rectification.getConfirmPerson());
                danger.setConfirmPersonName(rectification.getConfirmPersonName());
                danger.setRectificationAttachment(rectification.getRectificationAttachment());
                // 整改情况判断
                OverdueJudgmentUtil.setIsDelay3(danger, rectification);
            }
            factory.close();
        }
    }

    private void accidentAnalysis(List<AccidentBulletinAnalysis> operationAnalysisBeanList, SessionFactory
            factory, DepartmentTreeBean departmentTreeBean, String startTime, String endTime) {
        //查询当前部门下的所有网格（包括网格和部门）,不包含自己本身
        List<String> codeList = new ArrayList<>();
        if (departmentTreeBean != null) {
            codeList = nodeService.getChildCodeList(departmentTreeBean.getDepartmentCode());
            if (codeList == null) {
                codeList = new ArrayList<>();
            }
            codeList.add(departmentTreeBean.getDepartmentCode());
        }
        // 获取事故类型数据
        Map map = accidentTypeMap;
        map.put("codeList", codeList);
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        AccidentBulletinAnalysis analysis = factory.getMapper(DataAnalysisMapper.class).getAccidentAnalysis(map);
        analysis.setCorpCode(departmentTreeBean == null ? "776B361BFFAC4F00BBF459CD1303A8B2" : departmentTreeBean.getDepartmentCode());
        analysis.setCorpName(departmentTreeBean == null ? "水之眼" : departmentTreeBean.getName());
        operationAnalysisBeanList.add(analysis);
    }


    private void setMap() {
        try (SessionFactory factory = new SessionFactory()) {
            IndicationItemsMapper itemsMapper = factory.getMapper(IndicationItemsMapper.class);
            String nomarlDangerCount = itemsMapper.matchIndicationItems("隐患分级", "一般隐患") == null ? null :
                    itemsMapper.matchIndicationItems("隐患分级", "一般隐患").getId();
            if (StringUtils.isNotEmpty(nomarlDangerCount)) {
                map.put("nomarlDangerCount", nomarlDangerCount);
            }
            String importantDangerCont = itemsMapper.matchIndicationItems("隐患分级", "重大隐患") == null ? null :
                    itemsMapper.matchIndicationItems("隐患分级", "重大隐患").getId();
            if (StringUtils.isNotEmpty(importantDangerCont)) {
                map.put("importantDangerCont", importantDangerCont);
            }
            String managerDangetCount = itemsMapper.matchIndicationItems("隐患分类", "管理缺陷") == null ? null :
                    itemsMapper.matchIndicationItems("隐患分类", "管理缺陷").getId();
            if (StringUtils.isNotEmpty(managerDangetCount)) {
                map.put("managerDangetCount", managerDangetCount);
            }
            String deviceDangerCount = itemsMapper.matchIndicationItems("隐患分类", "设备设施隐患") == null ? null :
                    itemsMapper.matchIndicationItems("隐患分类", "设备设施隐患").getId();
            if (StringUtils.isNotEmpty(deviceDangerCount)) {
                map.put("deviceDangerCount", deviceDangerCount);
            }
            String meterialDangerCount = itemsMapper.matchIndicationItems("隐患分类", "物料隐患") == null ? null :
                    itemsMapper.matchIndicationItems("隐患分类", "物料隐患").getId();
            if (StringUtils.isNotEmpty(meterialDangerCount)) {
                map.put("meterialDangerCount", meterialDangerCount);
            }
            String personDangerCount = itemsMapper.matchIndicationItems("隐患分类", "人的不安全行为") == null ? null :
                    itemsMapper.matchIndicationItems("隐患分类", "人的不安全行为").getId();
            if (StringUtils.isNotEmpty(personDangerCount)) {
                map.put("personDangerCount", personDangerCount);
            }
            String goodsDangerCount = itemsMapper.matchIndicationItems("隐患分类", "物的不安全状态") == null ? null :
                    itemsMapper.matchIndicationItems("隐患分类", "物的不安全状态").getId();
            if (StringUtils.isNotEmpty(goodsDangerCount)) {
                map.put("goodsDangerCount", goodsDangerCount);
            }
            String enviropmentDangerCount = itemsMapper.matchIndicationItems("隐患分类", "环境因素") == null ? null :
                    itemsMapper.matchIndicationItems("隐患分类", "环境因素").getId();
            if (StringUtils.isNotEmpty(enviropmentDangerCount)) {
                map.put("enviropmentDangerCount", enviropmentDangerCount);
            }
            String unreformCount = itemsMapper.matchIndicationItems("隐患整改状态", "未整改") == null ? null :
                    itemsMapper.matchIndicationItems("隐患整改状态", "未整改").getId();
            if (StringUtils.isNotEmpty(unreformCount)) {
                map.put("unreformCount", unreformCount);
            }
            String alreadyReformCount1 = itemsMapper.matchIndicationItems("隐患整改状态", "已整改") == null ? null :
                    itemsMapper.matchIndicationItems("隐患整改状态", "已整改").getId();
            if (StringUtils.isNotEmpty(alreadyReformCount1)) {
                map.put("alreadyReformCount1", alreadyReformCount1);
            }
            String reformingCount = itemsMapper.matchIndicationItems("隐患整改状态", "整改中") == null ? null :
                    itemsMapper.matchIndicationItems("隐患整改状态", "整改中").getId();
            if (StringUtils.isNotEmpty(reformingCount)) {
                map.put("reformingCount", reformingCount);
            }
            String refuseReformCount = itemsMapper.matchIndicationItems("隐患整改状态", "整改驳回") == null ? null :
                    itemsMapper.matchIndicationItems("隐患整改状态", "整改驳回").getId();
            if (StringUtils.isNotEmpty(refuseReformCount)) {
                map.put("refuseReformCount", refuseReformCount);
            }
            String majorHazardSource = itemsMapper.matchIndicationItems("危险源级别", "重大") == null ? null :
                    itemsMapper.matchIndicationItems("危险源级别", "重大").getId();
            if (StringUtils.isNotEmpty(majorHazardSource)) {
                map.put("majorHazardSource", majorHazardSource);
            }
            String groupClass = itemsMapper.matchIndicationItems("检查层级", "班组级") == null ? null :
                    itemsMapper.matchIndicationItems("检查层级", "班组级").getId();
            if (StringUtils.isNotEmpty(groupClass)) {
                map.put("groupClass", groupClass);
            }
            String plateClass = itemsMapper.matchIndicationItems("检查层级", "班组级") == null ? null :
                    itemsMapper.matchIndicationItems("检查层级", "班组级").getId();
            if (StringUtils.isNotEmpty(plateClass)) {
                map.put("plateClass", plateClass);
            }
            String departmnetClass = itemsMapper.matchIndicationItems("检查层级", "班组级") == null ? null :
                    itemsMapper.matchIndicationItems("检查层级", "班组级").getId();
            if (StringUtils.isNotEmpty(departmnetClass)) {
                map.put("departmnetClass", departmnetClass);
            }
            String corpClass = itemsMapper.matchIndicationItems("检查层级", "班组级") == null ? null :
                    itemsMapper.matchIndicationItems("检查层级", "班组级").getId();
            if (StringUtils.isNotEmpty(corpClass)) {
                map.put("corpClass", corpClass);
            }
        }
    }

    private void setAccidentTypeMap() {
        try (SessionFactory factory = new SessionFactory()) {
            DictDataMapper dictDataMapper = factory.getMapper(DictDataMapper.class);
            DictData electricShock = dictDataMapper.matchDictData("事故类型", "触电");
            String electricShockType = null == electricShock ? null : electricShock.getId();
            if (StringUtils.isNotEmpty(electricShockType)) {
                accidentTypeMap.put("electricShockType", electricShockType);
            }
            DictData mechanicalInjury = dictDataMapper.matchDictData("事故类型", "机械伤害");
            String mechanicalInjuryType = null == mechanicalInjury ? null : mechanicalInjury.getId();
            if (StringUtils.isNotEmpty(mechanicalInjuryType)) {
                accidentTypeMap.put("mechanicalInjuryType", mechanicalInjuryType);
            }
            DictData otherInjury = dictDataMapper.matchDictData("事故类型", "其他伤害");
            String otherInjuryType = null == otherInjury ? null : otherInjury.getId();
            if (StringUtils.isNotEmpty(otherInjuryType)) {
                accidentTypeMap.put("otherInjuryType", otherInjuryType);
            }
            DictData liftingInjury = dictDataMapper.matchDictData("事故类型", "起重伤害");
            String liftingInjuryType = null == liftingInjury ? null : liftingInjury.getId();
            if (StringUtils.isNotEmpty(liftingInjuryType)) {
                accidentTypeMap.put("liftingInjuryType", liftingInjuryType);
            }
            DictData otherExplosions = dictDataMapper.matchDictData("事故类型", "其他爆炸");
            String otherExplosionsType = null == otherExplosions ? null : otherExplosions.getId();
            if (StringUtils.isNotEmpty(otherExplosionsType)) {
                accidentTypeMap.put("otherExplosionsType", otherExplosionsType);
            }
            DictData poisoningAndSuffocation = dictDataMapper.matchDictData("事故类型", "中毒与窒息");
            String poisoningAndSuffocationType = null == poisoningAndSuffocation ? null : poisoningAndSuffocation.getId();
            if (StringUtils.isNotEmpty(poisoningAndSuffocationType)) {
                accidentTypeMap.put("poisoningAndSuffocationType", poisoningAndSuffocationType);
            }
            DictData fire = dictDataMapper.matchDictData("事故类型", "火灾");
            String fireType = null == fire ? null : fire.getId();
            if (StringUtils.isNotEmpty(fireType)) {
                accidentTypeMap.put("fireType", fireType);
            }
            DictData scald = dictDataMapper.matchDictData("事故类型", "灼烫");
            String scaldType = null == scald ? null : scald.getId();
            if (StringUtils.isNotEmpty(scaldType)) {
                accidentTypeMap.put("scaldType", scaldType);
            }
            DictData fallFromHeight = dictDataMapper.matchDictData("事故类型", "高处坠落");
            String fallFromHeightType = null == fallFromHeight ? null : fallFromHeight.getId();
            if (StringUtils.isNotEmpty(fallFromHeightType)) {
                accidentTypeMap.put("fallFromHeightType", fallFromHeightType);
            }
            DictData objectStrike = dictDataMapper.matchDictData("事故类型", "物体打击");
            String objectStrikeType = null == objectStrike ? null : objectStrike.getId();
            if (StringUtils.isNotEmpty(objectStrikeType)) {
                accidentTypeMap.put("objectStrikeType", objectStrikeType);
            }
            DictData explode = dictDataMapper.matchDictData("事故类型", "瓦斯爆炸");
            String explodeType = null == explode ? null : explode.getId();
            if (StringUtils.isNotEmpty(explodeType)) {
                accidentTypeMap.put("explodeType", explodeType);
            }
            DictData vehicleInjury = dictDataMapper.matchDictData("事故类型", "车辆伤害");
            String vehicleInjuryType = null == vehicleInjury ? null : vehicleInjury.getId();
            if (StringUtils.isNotEmpty(vehicleInjuryType)) {
                accidentTypeMap.put("vehicleInjuryType", vehicleInjuryType);
            }
            DictData drowning = dictDataMapper.matchDictData("事故类型", "淹溺");
            String drowningType = null == drowning ? null : drowning.getId();
            if (StringUtils.isNotEmpty(drowningType)) {
                accidentTypeMap.put("drowningType", drowningType);
            }
            DictData containerExplosion = dictDataMapper.matchDictData("事故类型", "容器爆炸");
            String containerExplosionType = null == containerExplosion ? null : containerExplosion.getId();
            if (StringUtils.isNotEmpty(containerExplosionType)) {
                accidentTypeMap.put("containerExplosionType", containerExplosionType);
            }
            DictData collapse = dictDataMapper.matchDictData("事故类型", "坍塌");
            String collapseType = null == collapse ? null : collapse.getId();
            if (StringUtils.isNotEmpty(collapseType)) {
                accidentTypeMap.put("collapseType", collapseType);
            }
            DictData roofFallingPanel = dictDataMapper.matchDictData("事故类型", "冒顶片帮");
            String roofFallingPanelType = null == roofFallingPanel ? null : roofFallingPanel.getId();
            if (StringUtils.isNotEmpty(roofFallingPanelType)) {
                accidentTypeMap.put("roofFallingPanelType", roofFallingPanelType);
            }
            DictData permeable = dictDataMapper.matchDictData("事故类型", "透水");
            String permeableType = null == permeable ? null : permeable.getId();
            if (StringUtils.isNotEmpty(permeableType)) {
                accidentTypeMap.put("permeableType", permeableType);
            }
            DictData blasting = dictDataMapper.matchDictData("事故类型", "放炮");
            String blastingType = null == blasting ? null : blasting.getId();
            if (StringUtils.isNotEmpty(blastingType)) {
                accidentTypeMap.put("blastingType", blastingType);
            }
            DictData gunpowderExplosion = dictDataMapper.matchDictData("事故类型", "火药爆炸");
            String gunpowderExplosionType = null == gunpowderExplosion ? null : gunpowderExplosion.getId();
            if (StringUtils.isNotEmpty(gunpowderExplosionType)) {
                accidentTypeMap.put("gunpowderExplosionType", gunpowderExplosionType);
            }
            DictData boilerExplosion = dictDataMapper.matchDictData("事故类型", "锅炉爆炸");
            String boilerExplosionType = null == boilerExplosion ? null : boilerExplosion.getId();
            if (StringUtils.isNotEmpty(boilerExplosionType)) {
                accidentTypeMap.put("boilerExplosionType", boilerExplosionType);
            }
        }
    }
}
